package com.jiaquyun.jcps.mode.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.jiaquyun.jcps.mode.BaseViewModel
import com.jiaquyun.jcps.entity.OrderDetailsResponse
import com.jiaquyun.jcps.entity.PhotoResponse
import com.jiaquyun.jcps.mode.manager.OrderManager
import com.jiaquyun.jcps.utils.AMapLocationUtils
import com.lemlin.network.HttpServiceData
import com.lemlin.network.HttpServiceResponse
import com.lemlin.network.ViewModelSubscribe
import io.reactivex.disposables.Disposable

class RouteViewModel(application: Application) : BaseViewModel(application) {


    private val orderManager: OrderManager = OrderManager()

    val orderDetailsDataLiveData = MutableLiveData<HttpServiceResponse<OrderDetailsResponse>>()
    val baseServiceLiveData = MutableLiveData<HttpServiceResponse<HttpServiceData>>()

    /**
     * 手机号登录
     */
    fun orderDetails(riderOrderId: String) {
        AMapLocationUtils.instance()?.locationDataLiveData?.value?.let {
            val lat: String? = it["lat"]
            val lng: String? = it["lng"]
            if (lat.isNullOrEmpty() || lng.isNullOrEmpty())
                return@let
            val listener = ViewModelSubscribe<OrderDetailsResponse>(orderDetailsDataLiveData)
            val disposable: Disposable = orderManager.orderDetails(lat, lng, riderOrderId, listener)
            dispose.add(disposable)
        }
    }

    /**
     * 送达
     * */
    fun orderService(riderOrderId: String,images:String) {
        val listener = object : ViewModelSubscribe<HttpServiceData>(baseServiceLiveData) {}
        val disposable: Disposable = orderManager.orderService(riderOrderId,images, listener)
        dispose.add(disposable)
    }

}